@using Elsa.Studio.Workflows.Components.WorkflowDefinitionEditor.Components.ActivityProperties.Tabs
@using Elsa.Studio.Workflows.Components.WorkflowDefinitionEditor.Components.ActivityProperties.Tabs.Outputs.Components
@using Elsa.Studio.Extensions
@using Variant = MudBlazor.Variant
@inherits StudioComponentBase

<CascadingValue Value="ExpressionDescriptorProvider">
    <MudTabs Elevation="0" ApplyEffectsToContainer="true">

        <MudTabPanel Text="Input">
            @if (ActivityDescriptor?.Inputs.Any(x => x.IsBrowsable != false) == true)
            {
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    <InputsTab WorkflowDefinition="WorkflowDefinition" Activity="@Activity" ActivityDescriptor="@ActivityDescriptor" OnActivityUpdated="OnActivityUpdated"/>
                </ScrollableWell>
            }
            else
            {
                <Well>
                    <MudAlert Severity="Severity.Normal" Variant="Variant.Text">This activity does not have any input properties.</MudAlert>
                </Well>
            }
        </MudTabPanel>

        <MudTabPanel Text="Output">
            @if (ActivityDescriptor?.Outputs.Any(x => x.IsBrowsable != false) == true)
            {
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    <OutputsTab WorkflowDefinition="WorkflowDefinition" Activity="Activity" ActivityDescriptor="ActivityDescriptor" OnActivityUpdated="OnActivityUpdated"/>
                </ScrollableWell>
            }
            else
            {
                <Well>
                    <MudAlert Severity="Severity.Normal" Variant="Variant.Text">This activity does not have any output properties.</MudAlert>
                </Well>
            }
        </MudTabPanel>

        <MudTabPanel Text="Common">
            @if (Activity != null && ActivityDescriptor != null)
            {
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    <CommonTab Activity="@Activity" ActivityDescriptor="@ActivityDescriptor" OnActivityUpdated="OnActivityUpdated"/>
                </ScrollableWell>
            }
            else
            {
                <Well>
                    <MudAlert Severity="Severity.Normal" Variant="Variant.Text">This activity does not have any common properties.</MudAlert>
                </Well>
            }
        </MudTabPanel>
        
        @if (IsTaskActivity)
        {
            <MudTabPanel Text="Task">
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    <TaskTab Activity="Activity" ActivityDescriptor="ActivityDescriptor" OnActivityUpdated="OnActivityUpdated"/>
                </ScrollableWell>
            </MudTabPanel>
        }

        <MudTabPanel Text="Persistence">
              <ScrollableWell MaxHeight="VisiblePaneHeight">
                <PersistenceTab WorkflowDefinition="WorkflowDefinition" Activity="@Activity" ActivityDescriptor="@ActivityDescriptor" OnActivityUpdated="OnActivityUpdated" />
              </ScrollableWell>
         </MudTabPanel> 
               

        <MudTabPanel Text="Info">
            @if (ActivityDescriptor != null)
            {
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    <InfoTab ActivityDescriptor="@ActivityDescriptor"/>
                </ScrollableWell>
            }
        </MudTabPanel>

        @if (IsWorkflowAsActivity)
        {
            <MudTabPanel Text="Version">
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    <VersionTab Activity="Activity" ActivityDescriptor="ActivityDescriptor" OnActivityUpdated="OnActivityUpdated"/>
                </ScrollableWell>
            </MudTabPanel>
        }

        @foreach(var tab in PluginTabs)
        {
             <MudTabPanel Text="@tab.Title">
                <ScrollableWell MaxHeight="VisiblePaneHeight">
                    @tab.Render((new {WorkflowDefinition, Activity, ActivityDescriptor, OnActivityUpdated}).ToDictionary())
                </ScrollableWell>
            </MudTabPanel>
        }

    </MudTabs>
</CascadingValue>